Skip to content

Conversation

matiaslindgren
Copy link
Contributor

Comment on lines 275 to 282
# GH 62518
df4 = DataFrame(
columns=MultiIndex.from_arrays(
[["a", "a", "z", "z"], pd.Categorical([1, 2, 1, 2])],
),
dtype=object,
)
df4["z"] = df4["z"].astype("int64")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this a separate test that uses the exact code snippet in the original issue?

),
dtype=object,
)
meta["z"] = meta["z"].astype("int64")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, one more thing. Could you use tm.assert_frame.equal to assert that meta is equal to a new DataFrame that's the result of this casting?

@mroeschke mroeschke added this to the 3.0 milestone Oct 2, 2025
@mroeschke mroeschke added MultiIndex Categorical Categorical Data Type labels Oct 2, 2025
@mroeschke mroeschke merged commit 72ba35b into pandas-dev:main Oct 2, 2025
33 of 54 checks passed
@mroeschke
Copy link
Member

Thanks @matiaslindgren

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type MultiIndex
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Regression in DataFrame.__setitem__ with DataFrame, Categorical level of MultiIndex in pandas 3.x
2 participants